package com.relax.tcp.decode;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

public class MyDecode extends ByteToMessageDecoder {
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        short dataLength = in.readShort();
        Person person = new Person();
        byte[] bytes = new byte[dataLength];
        in.readBytes(bytes);
        String name = new String(bytes);
        person.setLength((long) dataLength);
        person.setName(name);
        System.out.println("解码读取到的数据为:" + person.toString());
        out.add(person);
    }
}
